package com.seres.enums;

import lombok.Getter;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description : 错误统一管理枚举
 * @Author : 杨松
 * @Date: 2020-06-24 11:11
 */
@Getter
public enum ErrorEnum {

    SUCCESS(200, "操作成功"),
    SUCCESS_AUTOHELPER(1, "操作成功"),
    SUCCESS_AUTOHELPER_JCZ(1, "操作成功"),
    SUCCESS_CHEWUTONG(0, "操作成功"),

    /**网关错误*/
    PARAM_ERROR(400,"参数错误"),
    NO_AUTHORIZATION(401,"你无权访问该链接"),
    TOKEN_EXPIRED(402,"当前登录已过期，请重新登录"),
    ONLY_ONE_DEVICES(403,"您的账号已在其他设备登录"),
    ACCESS_DENIED(405,"你没有该功能的访问权限"),
    USER_INFO_FAIL(406,"获取用户信息失败"),
    /**系统模块使用错误编码500-999*/
    SERVER_ERROR(500,"服务器错误"),
    ERROR_TABLE(501,"表未定义Mapper"),
    SERVER_REMOTE_ERROR(502,"获取远程信息失败"),
    ERROR_CHARACTER(503,"非法字符"),
    ERROR_SOURCE_NULL(504,"来源为空"),
    ERROR_STATION_UNION_RATE(505,"站盟配置费率出错,请检查"),
    ERROR_STATION_SUPPLY_RATE(505,"服务商配置费率出错,请检查"),
    ERROR_HEAD(506,"未知消息头"),
    ERROR_SIGN(507,"签名错误"),
    ERROR_NOT_PERMISSION(508,"您没有此功能权限，请联系客服"),
    ERROR_EXCLE_FORMAT(509,"文件格式为xls,请检查"),
    ERROR_EXCLE_ON_DATA(510,"文件未解析出数据,请检查"),
    ERROR_USER_COMPID(511,"用户机构编号查询失败"),
    ERROR_USER_DATA(512,"获取user信息失败"),
    ERROR_CHANNEL_DATA(513,"获取渠道信息失败,请稍后再试"),
    SQL_HANDLE_ERROR(514,"数据库操作失败"),
    SERVER_HANDLE_ERROR(515,"操作错误"),// 公用业务抛出错误
    REMIND_SETTING_ERROR(516,"该配置已存在"),
    UN_KNOW_TYPE(517,"不知道的配置类型"),
    ;

    /**
     * 错误编码
     */
    private int code;
    /**
     * 错误信息
     */
    private String msg;

    ErrorEnum(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    static ConcurrentHashMap<Integer, ErrorEnum> errors = new ConcurrentHashMap<>();

    static {
        for (ErrorEnum errorEnum : values()) {
            errors.put(errorEnum.getCode(), errorEnum);
        }
    }

    public static ErrorEnum parse(int code) {
        return errors.get(code);
    }
}
